import * as services from '../services';
const initTableState = {
  pageSize: 10,
  pageIndex: 1,
  total: 0,
  list: [],
};

// modal 实现
const Model = {
  namespace: 'indexModel',
  state: {
    listObj: {
      ...initTableState,
    },
  },

  reducers: {
    updateState(state, { res }) {
      // 更新state
      return {
        ...state,
        ...res,
      };
    },
  },
  effects: {
    // 获取当前用户
    *getData({ payload, mTitle, service }, { call, put, select }) {
      const { data } = yield call(services[service], payload);
      if (data) {
        yield put({ type: 'updateState', res: { [mTitle]: data } });
      }
      return data;
    },
  },
};

export default Model;
